import { type CSSProperties, camelize } from 'vue'
import { isObject } from '@vue/shared'

export const setStyle = (
  element: HTMLElement,
  styleName: CSSProperties | keyof CSSProperties,
  value?: string | number
) => {
  if (!element || !styleName) return

  if (isObject(styleName)) {
    Object.entries(styleName).forEach(([prop, value]) =>
      setStyle(element, prop as any, value)
    )
  } else {
    const key: any = camelize(styleName)
    element.style[key] = value as any
  }
}
